<!DOCTYPE HTML>
<html>

<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="utf-8">
  
  <title>Elasticsearch.Nest 教程系列 3-1 序列化：Custom Serialization | 自定义序列化 | DeepThought</title>
  <meta name="google-site-verification" content="Ei6mmDdf-cJwox1RvJOeX8Dc720fqWjZQu-Ww2BjBt4">
  
  <meta name="author" content="积慕">
  
  <meta name="description" content="Nest 7 教程,Nest7.x 教程,Elasticsearch.Nest,Elasticsearch.Nest 入门, NEST 入门,NEST上手, Nest 官方文档, NEST 翻译,Elasticsearch.Nest 中文,Elasticsearch.Nest 中文文档, Nest 中文文档,NET ElasticSearch,NET es,NEST 教程, Elasticsearch 客户端,Elasticsearch 7,Elasticsearch 7.x,NEST 7,NEST 7.x,Serialization,NEST序列化,NEST自定义序列化,JsonNetSerializer">
  
  
  <meta name="keywords" content="Nest 7 教程,Nest7.x 教程,Elasticsearch.Nest,Elasticsearch.Nest 入门, NEST 入门,NEST上手, Nest 官方文档, NEST 翻译,Elasticsearch.Nest 中文,Elasticsearch.Nest 中文文档, Nest 中文文档,NET ElasticSearch,NET es,NEST 教程, Elasticsearch 客户端,Elasticsearch 7,Elasticsearch 7.x,NEST 7,NEST 7.x,Serialization,NEST序列化,NEST自定义序列化,JsonNetSerializer">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

  
  <meta property="og:title" content="Elasticsearch.Nest 教程系列 3-1 序列化：Custom Serialization | 自定义序列化">
  <meta property="og:site_name" content="DeepThought">

  
  <meta property="og:image" content>
  

  <link href="https://pic.zhuliang.ltd/favicon.ico" rel="shortcut icon" type="image/x-icon">
  <link rel="alternate" href="/atom.xml" title="DeepThought" type="application/atom+xml">
  <link rel="stylesheet" href="/css/style.css" media="screen" type="text/css">

  <link rel="stylesheet" href="//at.alicdn.com/t/font_1187293_8fec2ou5fyx.css">

  <!-- <link rel="stylesheet" href="//cdn.bootcss.com/highlight.js/9.6.0/styles/github.min.css"> -->
  <!-- <script src="//cdn.bootcss.com/highlight.js/9.6.0/highlight.min.js"></script> -->
  <script src="/js/highlight.min.js"></script>

  <link rel="stylesheet" href="/css/markdown.css">

  <script src="/js/av-min.3.0.4.js"></script>
  <script src="/js/Valine.min.1.3.6.js"></script>

</head></html>

<body>
  <header id="header" class="inner"><div class="alignleft">
  <h1><a href="/">DeepThought</a></h1>
  <h2><a href="/">知识需沉淀，更需分享</a></h2>
</div>
<nav id="main-nav" class="alignright">
  <ul>
    
      <li><a href="/">首页</a></li>
    
      <li><a href="/about">关于我</a></li>
    
      <li><a href="/atom.xml">订阅RSS</a></li>
    
  </ul>
  <div class="clearfix"></div>
</nav>
<div class="clearfix"></div>
        </header>
  <div id="content" class="inner">
    <div id="main-col" class="alignleft"><div id="wrapper"><article class="post">
  
  <div class="post-content">
    <header>
      
        <div class="icon"></div>
      

 
      
  
    <h1 class="title">Elasticsearch.Nest 教程系列 3-1 序列化：Custom Serialization | 自定义序列化</h1>
  


      
        <time datetime="2020-01-15T08:17:01.000Z">
          create: 2020-01-15 16:17:01 | update: 2020-01-23 12:13:44
            <span style="float: right;">
    <span class="post-count" id="busuanzi_container_page_pv" style="display: inline;">
        
        本文总阅读量: <span id="busuanzi_value_page_pv"></span>&nbsp;次
        <span class="blueSeparate">&nbsp;|&nbsp;</span>
        
        <span class="post-count">文章总字数:&nbsp;2k&nbsp;字</span>
    <span class="blueSeparate">&nbsp;|&nbsp;</span>
    <span class="post-count">阅读约需:&nbsp;8&nbsp;分钟</span>
    <br>
</span>
</span>
        </time>
      
            
    </header>
    <div class="entry">
      
      <blockquote>
<ul>
<li>本系列博文是“伪”官方文档翻译（更加本土化），并非完全将官方文档进行翻译，而是在查阅、测试原始文档并转换为自己真知灼见后的“准”翻译。有不同见解 / 说明不周的地方，还请海涵、不吝拍砖 ：）</li>
<li>官方文档见此：<a href="https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/introduction.html" target="_blank" rel="noopener">https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/introduction.html</a></li>
<li>本系列对应的版本环境：<a href="mailto:ElasticSearch@7.3.1" target="_blank" rel="noopener">ElasticSearch@7.3.1</a>，<a href="mailto:NEST@7.3.1" target="_blank" rel="noopener">NEST@7.3.1</a>，IDE 和开发平台默认为 VS2019，.NET CORE 2.1</li>
</ul>
</blockquote>
<blockquote>
<p>NEST 的默认 JSON 序列化知道如何正确的序列化所有请求和响应类型，以及如何正确处理的你的 .NET 模型类。然而有的时候，你可能需要修改默认行为或者自定义你自己的序列化器，本章节将说明如何自定义以及扩展 NEST 类型。</p>
</blockquote>
<hr>
<p>目前 NEST 客户端已经完全移除了 SimpleJson 和 Newtonsoft.Json，转而使用内置的 Utf8Json—一种直接与 UTF-8 二进制文件直接协同工作的快速序列化器。</p>
<p>随着转而使用 UtfJson，NEST 团队在 7.x 阶段删除了部分原先在之前 NEST 客户端中存在的 JSON 特性，变动如下：</p>
<ul>
<li>由于性能原因，由 Utf8Json 生成的 JSON 不会缩进。如请求中的 JSON 不会缩进，哪怕指定了 SerializationFormatting.Indented。但 NEST 团队正在考虑公开缩进 JSON 的选项以便于开发和调试。</li>
<li>NEST 类型不能通过继承扩展。在 6.x 版本，可以通过派生该类型并注释这些新属性来为该类型包括其他属性。在当前使用 Utf8Json 进行序列化的时候，此方法将不起作用。</li>
<li>序列化器使用 Reflection.Emit，而 Utf8Json 使用 Reflection.Emit 来生成高效的格式化器。但并非所有平台都支持 Reflection.Emit，例如 UWP，Xamarin.iOS 和 Xamarin.Android。</li>
<li>Elasticsearch.Net.DynamicResponse 将 JSON 数组反序列化为 List<object>。SimpleJson 将 JSON 数组反序列化为 object[]。但出于分配和性能方面的原因，Utf8Json 将它们反序列化为 List<object>。</object></object></li>
<li>将 JSON 对象字段名称反序列化为 C＃ 类的属性时，Utf8Json 更加严格。在 6.x 版本中，内部使用 Json.NET 进行序列化，JSON 对象字段名称会先跟 C＃ 的类属性名完全匹配的进行匹配，之后再使用不区分大小写的进行匹配。但在 7.x 版本中（使用 Utf8Json 后），名称必须完全匹配。</li>
</ul>
<h1 id="注入新的序列化器"><a href="#注入新的序列化器" class="headerlink" title="注入新的序列化器"></a>注入新的序列化器</h1><p>通过注入新的序列化器，可以让你在_source，_fields 或希望写入和返回用户提供的值的任何地方对（反）序列化进行调用。</p>
<a id="more"></a>
<p>在 Nest 中，称这种序列化器为 SourceSerializer。</p>
<p>另外，在 Nest 中，还存在另外一个被称为 RequestResponseSerializer 的序列化器。该序列化器是内部用的，主要负责 Nest 库自身的一些请求和响应类型。</p>
<p>如果没有配置 SourceSerializer，那么内部使用的也是 SourceSerializer。</p>
<p>通过实现 IElasticsearchSerializer，可以实现你自己的序列化器。示例如下：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">public class VanillaSerializer : IElasticsearchSerializer
{
    public T Deserialize&lt;T&gt;(Stream stream) =&gt; throw new NotImplementedException();

    public object Deserialize(Type type, Stream stream) =&gt; throw new NotImplementedException();

    public Task&lt;T&gt; DeserializeAsync&lt;T&gt;(Stream stream, CancellationToken cancellationToken = default(CancellationToken)) =&gt;
        throw new NotImplementedException();

    public Task&lt;object&gt; DeserializeAsync(Type type, Stream stream, CancellationToken cancellationToken = default(CancellationToken)) =&gt;
        throw new NotImplementedException();

    public void Serialize&lt;T&gt;(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented) =&gt;
        throw new NotImplementedException();

    public Task SerializeAsync&lt;T&gt;(T data, Stream stream, SerializationFormatting formatting = SerializationFormatting.Indented,
        CancellationToken cancellationToken = default(CancellationToken)) =&gt;
        throw new NotImplementedException();
}
</code></pre>
<p>使用自定义的序列化器是在 ConnectionSettings 的构造函数中进行指定的，如下：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var pool = new SingleNodeConnectionPool(new Uri(&quot;http://localhost:9200&quot;));
var connectionSettings = new ConnectionSettings(
    pool,
    sourceSerializer: (builtin, settings) =&gt; new VanillaSerializer()); 
var client = new ElasticClient(connectionSettings);
</code></pre>
<p>注入序列化器使用<strong>委托</strong>的原因：</p>
<ul>
<li>有的时候，你的 POCO 类由于某些原因，需要内嵌 NEST 类型（如你可能需要用到过滤，这个时候你希望获取文档中的 _source），如下：</li>
</ul>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">public class MyPercolationDocument
{
    public QueryContainer Query { get; set; }
    public string Category { get; set; }
}
</code></pre>
<ul>
<li>诸如 QueryContainer 或者其他 NEST 的类型有可能会作为文档的 _source 的一部分，而自定义的序列化器并不知道如何处理这些 NEST 类型，因此自定义序列化器需要将 NEST 类型的序列化过程委派给 NEST 内置的序列化器，通过委托，就可以应对这种场景。</li>
</ul>
<h1 id="JsonNetSerializer"><a href="#JsonNetSerializer" class="headerlink" title="JsonNetSerializer"></a>JsonNetSerializer</h1><p>NEST 团队提供了一个单独的 NEST.JsonNetSerializer 包，该包有助于使用 Json.NET 组成自定义 SourceSerializer，该包可以将已知 NEST 类型的序列化委派回内置的 RequestResponseSerializer。如果要控制使用 Json.NET 从 Elasticsearch 存储和检索文档及值的方式，而又不干扰 NEST 内部使用 Json.NET 的方式，则此包也很有用。</p>
<p>示例：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var pool = new SingleNodeConnectionPool(new Uri(&quot;http://localhost:9200&quot;));
var connectionSettings =
    new ConnectionSettings(pool, sourceSerializer: JsonNetSerializer.Default);
var client = new ElasticClient(connectionSettings);
</code></pre>
<p>JsonNetSerializer.Default 是语法糖，实际为：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var pool = new SingleNodeConnectionPool(new Uri(&quot;http://localhost:9200&quot;));
var connectionSettings = new ConnectionSettings(
    pool,
    sourceSerializer: (builtin, settings) =&gt; new JsonNetSerializer(builtin, settings));
var client = new ElasticClient(connectionSettings);
</code></pre>
<h1 id="Serializers-派生类"><a href="#Serializers-派生类" class="headerlink" title="Serializers 派生类"></a>Serializers 派生类</h1><p>如果你想要更加显式自定义，则可以继承 ConnectionSettingsAwareSerializerBase 并重写CreateJsonSerializerSettings 和 ModifyContractResolver方法，如下：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">public class MyFirstCustomJsonNetSerializer : ConnectionSettingsAwareSerializerBase
{
    public MyFirstCustomJsonNetSerializer(IElasticsearchSerializer builtinSerializer, IConnectionSettingsValues connectionSettings)
        : base(builtinSerializer, connectionSettings) { }

    protected override JsonSerializerSettings CreateJsonSerializerSettings() =&gt;
        new JsonSerializerSettings
        {
            NullValueHandling = NullValueHandling.Include
        };

    protected override void ModifyContractResolver(ConnectionSettingsAwareContractResolver resolver) =&gt;
        resolver.NamingStrategy = new SnakeCaseNamingStrategy();
}
</code></pre>
<ul>
<li>这里显式指定了 Json.Net 的命名策略为 SnakeCaseNamingStrategy。</li>
<li>JsonSerializerSettings 包含 null 属性</li>
<li>不影响 NEST 自己的类型如何序列化。</li>
<li>此外，由于此序列化器知道内置的序列化器，因此我们可以自动注入JsonConverter来处理可能出现在源中的已知 NEST 类型，如上面的 QueryContainer。</li>
</ul>
<h2 id="示例：通过文档类型来说明"><a href="#示例：通过文档类型来说明" class="headerlink" title="示例：通过文档类型来说明"></a>示例：通过文档类型来说明</h2><p>模型</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">public class MyDocument
{
    public int Id { get; set; }

    public string Name { get; set; }

    public string FilePath { get; set; }

    public int OwnerId { get; set; }

    public IEnumerable&lt;MySubDocument&gt; SubDocuments { get; set; }
}

public class MySubDocument
{
    public string Name { get; set; }
}
</code></pre>
<p>注入序列化器：</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var pool = new SingleNodeConnectionPool(new Uri(&quot;http://localhost:9200&quot;));
var connectionSettings = new ConnectionSettings(
    pool,
    connection: new InMemoryConnection(), 
    sourceSerializer: (builtin, settings) =&gt; new MyFirstCustomJsonNetSerializer(builtin, settings))
    .DefaultIndex(&quot;my-index&quot;);

var client = new ElasticClient(connectionSettings);
</code></pre>
<p>索引一份文档到 ES 中</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var document = new MyDocument
{
    Id = 1,
    Name = &quot;My first document&quot;,
    OwnerId = 2
};

var ndexResponse = client.IndexDocument(document);
</code></pre>
<p>以上文档将会被序列化为：</p>
<p></p><p class="code-caption" data-lang="json" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="json">{
  &quot;id&quot;: 1,
  &quot;name&quot;: &quot;My first document&quot;,
  &quot;file_path&quot;: null,
  &quot;owner_id&quot;: 2,
  &quot;sub_documents&quot;: null
}
</code></pre>
<ul>
<li>符合 MyFirstCustomJsonNetSerializer 中设定的数据.</li>
</ul>
<h2 id="序列化-Type-信息"><a href="#序列化-Type-信息" class="headerlink" title="序列化 Type 信息"></a>序列化 Type 信息</h2><p>这是另一个自定义序列化器的例子，自定义的解析器将在文档的序列化 JSON 中包含类型名称，当返回的集合中包含协变类型的时候，将会很有用。</p>
<p>定义序列化器 </p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">public class MySecondCustomContractResolver : ConnectionSettingsAwareContractResolver
{
    public MySecondCustomContractResolver(IConnectionSettingsValues connectionSettings)
        : base(connectionSettings) { }

    protected override JsonContract CreateContract(Type objectType)
    {
        var contract = base.CreateContract(objectType);
        if (contract is JsonContainerContract containerContract)
        {
            if (containerContract.ItemTypeNameHandling == null)
                containerContract.ItemTypeNameHandling = TypeNameHandling.None;
        }

        return contract;
    }
}

public class MySecondCustomJsonNetSerializer : ConnectionSettingsAwareSerializerBase
{
    public MySecondCustomJsonNetSerializer(IElasticsearchSerializer builtinSerializer, IConnectionSettingsValues connectionSettings)
        : base(builtinSerializer, connectionSettings) { }

    protected override JsonSerializerSettings CreateJsonSerializerSettings() =&gt;
        new JsonSerializerSettings
        {
            TypeNameHandling = TypeNameHandling.All,
            NullValueHandling = NullValueHandling.Ignore,
            TypeNameAssemblyFormatHandling = TypeNameAssemblyFormatHandling.Simple
        };

    protected override ConnectionSettingsAwareContractResolver CreateContractResolver() =&gt;
        new MySecondCustomContractResolver(ConnectionSettings); 
}
</code></pre>
<ul>
<li>重写 resolver</li>
</ul>
<p>注入自定义序列化器</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">var pool = new SingleNodeConnectionPool(new Uri(&quot;http://localhost:9200&quot;));
var connectionSettings = new ConnectionSettings(
        pool,
        connection: new InMemoryConnection(),
        sourceSerializer: (builtin, settings) =&gt; new MySecondCustomJsonNetSerializer(builtin, settings))
    .DefaultIndex(&quot;my-index&quot;);

var client = new ElasticClient(connectionSettings);
</code></pre>
<p>添加以下文档到 ES 中</p>
<p></p><p class="code-caption" data-lang="csharp" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="csharp">
var document = new MyDocument
{
    Id = 1,
    Name = &quot;My first document&quot;,
    OwnerId = 2,
    SubDocuments = new []
    {
        new MySubDocument { Name = &quot;my first sub document&quot; },
        new MySubDocument { Name = &quot;my second sub document&quot; },
    }
};

var ndexResponse = client.IndexDocument(document);
</code></pre>
<p>序列化结果：</p>
<p></p><p class="code-caption" data-lang="json" data-line_number="backend" data-trim_indent="backend" data-label_position="outer" data-labels_left="Code" data-labels_right=":" data-labels_copy="Copy Code"><span class="code-caption-label"></span></p><p></p>
<pre><code class="json">{
  &quot;$type&quot;: &quot;Tests.ClientConcepts.HighLevel.Serialization.GettingStarted+MyDocument, Tests&quot;,
  &quot;id&quot;: 1,
  &quot;name&quot;: &quot;My first document&quot;,
  &quot;ownerId&quot;: 2,
  &quot;subDocuments&quot;: [
    {
      &quot;name&quot;: &quot;my first sub document&quot;
    },
    {
      &quot;name&quot;: &quot;my second sub document&quot;
    }
  ]
}
</code></pre>
<ul>
<li>类型信息将针对外部 MyDocument 实例进行序列化，但不会针对 SubDocuments 集合中的每个MySubDocument 实例进行序列化。</li>
</ul>
<p>在实现派生自 ConnectionSettingsAwareContractResolver 的自定义解析器时，请注意不要更改 NEST 类型的解析器的行为；这样做会导致意外的行为。</p>

      

      <div>
        
        <div style="background-color: rgb(255, 23, 0);user-select: auto;height: 3px;width:100%;margin-top: 40px;margin-bottom:15px;"></div>

<!-- <p>常言道：学然后知不足，教然后知困。</p>
<p>我知道你的焦虑，一起共进加油：P</p>
<p>关不关注都无所谓，会根据生活节奏紧凑度定期分享些开发经验、搬砖生涯、痛点、感悟。</p>
<p>
        <img src="https://pic.zhuliang.ltd/20191213133908.gif" alt="欢迎关注我的订阅号：P" />
</p> -->
<ul class="post-copyright" style="margin-left:0px;">
    <li class="post-copyright-author">
        <strong>本文作者：</strong>积慕
    </li>
    <li class="post-copyright-link">
        <strong>本文链接：</strong>
        <a href="/2020/01/backend/Elasticsearch-Nest-custom-serialization.html" title="Elasticsearch.Nest 教程系列 3-1 序列化：Custom Serialization | 自定义序列化">https://blog.zhuliang.ltd/2020/01/backend/Elasticsearch-Nest-custom-serialization.html</a>
    </li>
    <li class="post-copyright-license">
        <strong>版权： </strong>
        本站文章均采用 <a href="http://creativecommons.org/licenses/by-nc-sa/3.0/cn/" rel="external nofollow"
            target="_blank">CC BY-NC-SA 3.0 CN</a> 许可协议，请勿用于商业，转载注明出处！
    </li>
</ul>
        
      </div>
    </div>

    <footer>
      
      
  
  <div class="categories">
    <a href="/categories/backend/">backend</a>
  </div>

      
  
  <div class="tags">
    <a href="/tags/教程/">教程</a>, <a href="/tags/Elasticsearch-Nest系列/">Elasticsearch.Nest系列</a>, <a href="/tags/Elasticsearch/">Elasticsearch</a>
  </div>

      <!-- 
  <div class="addthis addthis_toolbox addthis_default_style">
    
    
      <a class="addthis_button_tweet"></a>
    
    
      <a class="addthis_button_google_plusone" g:plusone:size="medium"></a>
    
    
      <a class="addthis_button_pinterest_pinit" pi:pinit:layout="horizontal"></a>
    
    <a class="addthis_counter addthis_pill_style"></a>
  </div>
  <script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js"></script>
 -->
      
      <div class="clearfix"></div>
    </footer>
  </div>
</article>

<!-- 
<section id="comment">
  <h1 class="title">留言</h1>

  <div id="vcomments" style="background-color: #fff"></div>
  <script>
    new Valine({
      el: '#vcomments',
      appId: 'aTPKmG6tjDo3CbIXzAPzrj4X-gzGzoHsz',
      appKey: 'hNgWFneNpEcMnBJclPQnDgsd',
      notify: true,
      verify: true, //验证码
      avatar: 'monsterid', //https://valine.js.org/avatar.html
      placeholder: '请输入你的评论'
    })
  </script>
</section>
 --> <!--启用/关闭 LeanCloud 评论--></div></div>
    <aside id="sidebar" class="alignright">
  
<div class="widget tag">
  <h3 class="title"><i class="iconfont icon-category"></i>&nbsp;&nbsp;分类</h3>
  <ul class="entry">
  
    <li><a href="/categories/Obsidian/">Obsidian</a><small>1</small></li>
  
    <li><a href="/categories/PowerUser/">PowerUser</a><small>4</small></li>
  
    <li><a href="/categories/backend/">backend</a><small>57</small></li>
  
    <li><a href="/categories/frontend/">frontend</a><small>9</small></li>
  
    <li><a href="/categories/operations/">operations</a><small>5</small></li>
  
    <li><a href="/categories/提前退休/">提前退休</a><small>2</small></li>
  
  </ul>
</div>


  
<div class="widget tag">
  <h3 class="title"><i class="iconfont icon-new3"></i>&nbsp;&nbsp;最新文章</h3>
  <ul class="entry">
    
      <li>
        <a href="/2024/11/PowerUser/install-docker-in-pve-lxc.html">1. 通过 PVE LXC 搭建 docker 环境</a>
      </li>
    
      <li>
        <a href="/2024/11/Obsidian/obsidian-render-pie-chart.html">2. 2 套用于 obsidian 的生成时间占用饼图脚本示例，基于 templater， charts，echarts+dataview</a>
      </li>
    
      <li>
        <a href="/2024/10/PowerUser/fix-ios18-samba-readonly-issue.html">3. 解决 ios 18（包括ipadOS 18） 下通过文件(files app)连接 samba 服务器，目录变成只读权限的问题</a>
      </li>
    
      <li>
        <a href="/2023/07/operations/how-to-use-pm2.html">4. PM2 的安装、配置和使用</a>
      </li>
    
      <li>
        <a href="/2023/07/backend/expose-intranet-netcoreapi-to-internet.html">5. 通过 DDNS+显性URL 把内网部署的.NET CORE WEBAPI 项目暴露到公网中</a>
      </li>
    
  </ul>
</div>


  
<div class="widget tag">
  <h3 class="title"><i class="iconfont icon-tag"></i>&nbsp;&nbsp;标签</h3>
  <ul class="entry">
  
    <li><a href="/tags/net-core/">.net core</a><small>12</small></li>
  
    <li><a href="/tags/Debian/">Debian</a><small>2</small></li>
  
    <li><a href="/tags/Docker/">Docker</a><small>1</small></li>
  
    <li><a href="/tags/Elasticsearch/">Elasticsearch</a><small>35</small></li>
  
    <li><a href="/tags/Elasticsearch-Nest系列/">Elasticsearch.Nest系列</a><small>35</small></li>
  
    <li><a href="/tags/Obsidian/">Obsidian</a><small>1</small></li>
  
    <li><a href="/tags/PVE/">PVE</a><small>2</small></li>
  
    <li><a href="/tags/StackExchange-Redis系列/">StackExchange.Redis系列</a><small>12</small></li>
  
    <li><a href="/tags/centos/">centos</a><small>3</small></li>
  
    <li><a href="/tags/flex/">flex</a><small>1</small></li>
  
    <li><a href="/tags/ios/">ios</a><small>1</small></li>
  
    <li><a href="/tags/javascript/">javascript</a><small>1</small></li>
  
    <li><a href="/tags/linux/">linux</a><small>4</small></li>
  
    <li><a href="/tags/nginx/">nginx</a><small>2</small></li>
  
    <li><a href="/tags/nuget/">nuget</a><small>2</small></li>
  
    <li><a href="/tags/react/">react</a><small>6</small></li>
  
    <li><a href="/tags/styled-components/">styled-components</a><small>1</small></li>
  
    <li><a href="/tags/内网穿透/">内网穿透</a><small>4</small></li>
  
    <li><a href="/tags/培训讲义/">培训讲义</a><small>2</small></li>
  
    <li><a href="/tags/基础知识/">基础知识</a><small>2</small></li>
  
    <li><a href="/tags/性能优化/">性能优化</a><small>2</small></li>
  
    <li><a href="/tags/教程/">教程</a><small>64</small></li>
  
    <li><a href="/tags/理财/">理财</a><small>2</small></li>
  
    <li><a href="/tags/生命周期/">生命周期</a><small>1</small></li>
  
    <li><a href="/tags/经验/">经验</a><small>4</small></li>
  
  </ul>
</div>


  
  <script type="text/javascript" charset="utf-8" src="/js/tagcloud.js"></script>
  <script type="text/javascript" charset="utf-8" src="/js/tagcanvas.js"></script>
  <div class="widget tag">
    <h3 class="title"><i class="iconfont icon-cloud1"></i>&nbsp;&nbsp;标签云</h3>
    <div id="myCanvasContainer" class="widget tagcloud">
      <canvas width="250" height="250" id="resCanvas" style="width:100%">
        <a href="/tags/net-core/" style="font-size: 17.14px;">.net core</a> <a href="/tags/Debian/" style="font-size: 11.43px;">Debian</a> <a href="/tags/Docker/" style="font-size: 10px;">Docker</a> <a href="/tags/Elasticsearch/" style="font-size: 18.57px;">Elasticsearch</a> <a href="/tags/Elasticsearch-Nest系列/" style="font-size: 18.57px;">Elasticsearch.Nest系列</a> <a href="/tags/Obsidian/" style="font-size: 10px;">Obsidian</a> <a href="/tags/PVE/" style="font-size: 11.43px;">PVE</a> <a href="/tags/StackExchange-Redis系列/" style="font-size: 17.14px;">StackExchange.Redis系列</a> <a href="/tags/centos/" style="font-size: 12.86px;">centos</a> <a href="/tags/flex/" style="font-size: 10px;">flex</a> <a href="/tags/ios/" style="font-size: 10px;">ios</a> <a href="/tags/javascript/" style="font-size: 10px;">javascript</a> <a href="/tags/linux/" style="font-size: 14.29px;">linux</a> <a href="/tags/nginx/" style="font-size: 11.43px;">nginx</a> <a href="/tags/nuget/" style="font-size: 11.43px;">nuget</a> <a href="/tags/react/" style="font-size: 15.71px;">react</a> <a href="/tags/styled-components/" style="font-size: 10px;">styled-components</a> <a href="/tags/内网穿透/" style="font-size: 14.29px;">内网穿透</a> <a href="/tags/培训讲义/" style="font-size: 11.43px;">培训讲义</a> <a href="/tags/基础知识/" style="font-size: 11.43px;">基础知识</a> <a href="/tags/性能优化/" style="font-size: 11.43px;">性能优化</a> <a href="/tags/教程/" style="font-size: 20px;">教程</a> <a href="/tags/理财/" style="font-size: 11.43px;">理财</a> <a href="/tags/生命周期/" style="font-size: 10px;">生命周期</a> <a href="/tags/经验/" style="font-size: 14.29px;">经验</a>
      </canvas>
    </div>
  </div>




</aside>
    <div class="clearfix"></div>
  </div>
  <footer id="footer" class="inner"><div class="alignleft">

  
  &copy; 2018 - 2024 &nbsp;<a href='/about'>积慕</a>
  
  &nbsp;&nbsp;<a href='https://www.cnblogs.com/deepthought/'>我的博客园地址</a>
  &nbsp;&nbsp;finalclassic#outlook.com
</div>

<div class="clearfix"></div>
<div>
  本站主题基于：<a href='https://github.com/hexojs/hexo-theme-light' rel="external nofollow">hexo-theme-light</a>
</div>
<div id="busuanzi_container_site_pv">
  本站总访问量&nbsp;<span id="busuanzi_value_site_pv"></span>&nbsp;次
</div>
<div style="width:300px;margin:0 auto; padding:20px 0;">
  <a target="_blank" href="http://www.beian.gov.cn/portal/registerSystemInfo?recordcode=31011702004805" style="display:inline-block;text-decoration:none;height:20px;line-height:20px;">
    <img src="https://pic.zhuliang.ltd/20200102164648.png" style="float:left;"><p style="float:left;height:20px;line-height:20px;margin: 0px 0px 0px 5px; color:#939393;">沪公网安备 31011702004805号</p></a>
</div></footer>
  <script src="/js/jquery-2.0.3.min.js"></script>
<script src="/js/jquery.imagesloaded.min.js"></script>
<script src="/js/gallery.js"></script>




<link rel="stylesheet" href="/fancybox/jquery.fancybox.css" media="screen" type="text/css">
<script src="/fancybox/jquery.fancybox.pack.js"></script>
<script type="text/javascript">
(function($){
  $('.fancybox').fancybox();
})(jQuery);
</script>


<script type="text/javascript">
hljs.initHighlightingOnLoad();
</script>

<!-- <script src="/js/busuanzi.pure.mini.js"></script> -->
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
<script>
    var _hmt = _hmt || [];
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?ea793b9c8d6b31df666a6bc15038e246";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
    })();
</script>
<script>
    (function () {
        var bp = document.createElement('script');
        var curProtocol = window.location.protocol.split(':')[0];
        if (curProtocol === 'https') {
            bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
        }
        else {
            bp.src = 'http://push.zhanzhang.baidu.com/push.js';
        }
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(bp, s);
    })();
</script>
</body>
</html>
